package com.mooc.user.controller;

import com.mooc.user.common.RestCode;
import com.mooc.user.common.RestResponse;
import com.mooc.user.model.City;
import com.mooc.user.service.CityService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class HouseController {

    @Autowired
    private CityService cityService;

    @RequestMapping("/house/getAllCitys")
    public RestResponse<List<City>> toAdd(ModelMap modelMap) {
        List<City> cities = cityService.selectAllCities();
        if(CollectionUtils.isEmpty(cities)){
            return RestResponse.error(RestCode.CITY_NOT_FOUND);
        }
         return RestResponse.success(cities);

    }

}
